from django.db import models
# Create your models here.
class OrderMaster(models.Model):
    # sn 订单编号 yyyymmddnnnnnnnn
    sn = models.CharField(max_length=50, verbose_name=u'订单编号')
    # 收货店铺
    shops = models.OneToOneField(to='Shops.Shops_base',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'收货店铺')
    # user 下单人IDk
    user = models.ForeignKey(to='user.User_Account',on_delete=models.CASCADE)
    # shippingUser 收货人姓名’,
    shipping_user = models.CharField(max_length=30, verbose_name=u'收货人姓名')
    contact = models.CharField(max_length=300, verbose_name=u'联系方式')
    desc = models.CharField(max_length=300, verbose_name=u'备注')
    # province SMALLINT NOT NULL COMMENT ‘省’,
    province = models.CharField(max_length=10, verbose_name=u'省')
    # city SMALLINT NOT NULL COMMENT ‘市’,
    city = models.CharField(max_length=10, verbose_name=u'市')
    # district SMALLINT NOT NULL COMMENT ‘区’,
    district = models.CharField(max_length=10, verbose_name=u'区')
    # address VARCHAR(100) NOT NULL COMMENT ‘地址’,
    address = models.CharField(max_length=10, verbose_name=u'地址')
    # payment_method = models.CharField(
    #     max_length=30, verbose_name=u'支付方式', choices=ROLE)
    # order_money DECIMAL(8,2) NOT NULL COMMENT ‘订单金额’,
    order_money = models.FloatField(null=True, blank=True, verbose_name=u'订单金额')
    # district_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 COMMENT ‘优惠金额’,
    district_money = models.FloatField(null=True, blank=True, verbose_name=u'优惠金额')
    # shipping_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 COMMENT ‘运费金额’,
    shipping_money = models.FloatField(null=True, blank=True, verbose_name=u'运费金额')
    # payment_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 COMMENT ‘支付金额’,
    payment_money = models.FloatField(null=True, blank=True, verbose_name=u'支付金额')
    # shipping_comp_name VARCHAR(10) COMMENT ‘快递公司名称’,
    shipping_comp_name = models.CharField(null=True, blank=True,max_length=10, verbose_name=u'快递公司名称')
    # shipping_sn VARCHAR(50) COMMENT ‘快递单号’,
    shipping_sn = models.CharField(max_length=50,null=True, blank=True, verbose_name=u'快递单号')
    # create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘下单时间’,
    create_time = models.DateTimeField(auto_now_add=True,verbose_name=u'创建日期-下单时间')   
    # shipping_time DATETIME COMMENT ‘发货时间’,
    # pay_time DATETIME COMMENT ‘支付时间’,
    # receive_time DATETIME COMMENT ‘收货时间’,
    # order_status TINYINT NOT NULL DEFAULT 0 COMMENT ‘订单状态’,
    # payment_method TINYINT NOT NULL COMMENT ‘支付方式：1现金，2余额，3网银，4支付宝，5微信’,
    payment_method = models.CharField(
        null=True, blank=True,
        max_length=10, verbose_name=u'支付方式', choices=(
        (u'1', u'现金'),
        (u'2', u'余额'),
        (u'3', u'网银'),
        (u'4', u'支付宝'),
        (u'5', u'微信'),
    ))
    order_status = models.CharField(
        max_length=10, verbose_name=u'订单状态', choices=(
        (u'1', u'待付款'),
        (u'2', u'待收货'),
        (u'3', u'已签收'),
        (u'4', u'申请退款'),
    ))
    last_time = models.DateTimeField(auto_now=True,verbose_name=u'最后一次修改日期')  
    
class orderDetail(models.Model):

    # order_id INT UNSIGNED NOT NULL COMMENT ‘订单表ID’,
    order_id = models.ForeignKey('OrderMaster',on_delete=models.CASCADE)
    
    # product_id INT UNSIGNED NOT NULL COMMENT ‘订单商品ID’,
    goods_id = models.ForeignKey('Goods.GoodsBase',on_delete=models.CASCADE)

    src = models.CharField(max_length=300, verbose_name=u'图片地址')

    # product_name VARCHAR(50) NOT NULL COMMENT ‘商品名称’,
    goods_name = models.CharField(max_length=100, verbose_name=u'商品名称')

    attr = models.CharField(max_length=100, verbose_name=u'套餐名称')

    # product_cnt INT NOT NULL DEFAULT 1 COMMENT ‘购买商品数量’,
    product_num = models.IntegerField(null=True, blank=True, verbose_name=u'购买商品数量')

    # product_price DECIMAL(8,2) NOT NULL COMMENT ‘购买商品单价’,
    product_price = models.FloatField(null=True, blank=True, verbose_name=u'购买商品单价')

    # average_cost DECIMAL(8,2) NOT NULL COMMENT ‘平均成本价格’,
    # weight FLOAT COMMENT ‘商品重量’,
    # fee_money DECIMAL(8,2) NOT NULL DEFAULT 0.00 COMMENT ‘优惠分摊金额’,
    # w_id INT UNSIGNED NOT NULL COMMENT ‘仓库ID’,
    # modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘最后修改时间’,
    # PRIMARY KEY pk_orderdetailid(order_detail_id)
    # )ENGINE = innodb COMMENT ‘订单详情表’

    

    # class Meta:
    #     verbose_name = _("")
    #     verbose_name_plural = _("s")

    def __str__(self):
        return self.sn

    # def get_absolute_url(self):
        # return reverse("_detail", kwargs={"pk": self.pk})
